5.1 Calling the API from an external system

Once you have obtained an access token, you can call the API.

Present the access token in an Authorization header with a type of Bearer (as detailed in the token_type option in the returned JSON containing your access token).

Important: You must keep track of the lifetime of the token, and request a new token when the current token has expired. Avoid obtaining a new access token if the previous token is still valid, as this generates unnecessary records in the Logons table in the MyID database, and may impact your system performance.

For example, to view the details of a particular person, you use the following:

GET /api/People/{id}

This method requires a parameter dirInfo and the ID of the person – this example uses the following ID:

53F2A29B-376B-4600-867C-2E5BD95AE222

See the API documentation for the particular requirements for each method.

For example, using cURL:

Copy
curl -k -i -X GET "https://myserver.example.com/rest.core/api/People/53F2A29B-376B-4600-867C-2E5BD95AE222" -d "dirInfo=true" -H "Authorization: Bearer <token string>"

or using PowerShell:

Copy
# Access token for the API
$token = "<token string>"

# Set the body of the request. The parameters depend on the method being used; 
# see the Swagger-based API documentation for details.
$body = @{dirInfo='true'
    }

# Set the headers for the request
$header = @{Authorization="Bearer $token"
    }

# Call the method. This example obtains the information about a particular 
# person. The user configured for the API must have access to this feature 
# through their role assignment, and must have scope that allows them to 
# view the details of the specified person.
Invoke-WebRequest -Method GET -Uri 'https://myserver.example.com/rest.core/api/People/53F2A29B-376B-4600-867C-2E5BD95AE222' -body $body -Headers $header | Select-Object -Expand Content

# Wait for a keypress
Write-Host "`r`nPress any key to continue..." -ForegroundColor Yellow

[void][System.Console]::ReadKey($true)